{extend name="public/base" /}
{block name="container"}
<div class="panel panel-default">
  <div class="panel-heading">
    <h4 class="panel-title">添加用户</h4>
  </div>
  <div class="panel-body panel-body-nopadding">

    <form class="form-horizontal form-bordered" id="submitForm" action="" method="post" >
      <div class="form-group">
        <label class="col-sm-3 control-label">产品名称:</label>
        <div class="col-sm-6">
          <input type="text" class="form-control" name="name" placeholder="请输入用户名"  value="{$data.name}"  readonly>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">产品编号:</label>
        <div class="col-sm-6">
          <input type="text" class="form-control" name="code" placeholder="请输入密码" value="{$data.code}" readonly>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">面料编号:</label>
        <div class="col-sm-6">
          <input type="text" class="form-control" name="ml_num" placeholder="请输入确认密码" value="{$data.ml_num ?? ''}" readonly>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label"><span>*</span>面料属性：</label>
        <div class="col-sm-6">
          <input type="text" class="form-control" placeholder="真实姓名" name="ml_style" value="{$data.ml_style ?? ''}"  readonly>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label"><span>*</span>剩余库存：</label>
        <div class="col-sm-6">
          <input type="text" class="form-control" placeholder="手机号" name="shengyu_num" value="{$data.shengyu_num ?? ''}"  readonly>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label"><span>*</span>可分配数量：</label>
        <div class="col-sm-6">
          <input type="text" class="form-control" placeholder="邮箱" name="fenpei_num" id="fenpei_num" value="{$data['fenpei_num'] ?? ''}" readonly>
        </div>
      </div>
          <div class="form-group" id="tianjia">
                        <label class="col-sm-3 control-label">分配库存：</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                              <span class="input-group-btn">
                                <button type="button" class="btn btn-default" onclick="addattrs()">添加</button>
                              </span>
                              <input type="text" class="form-control" id="attrs_title"  value="" placeholder="请填入分配数量"/>
                            </div>
                        </div>
                    </div>

      <div class="panel-footer">
       <div class="row">
        <div class="col-sm-6 col-sm-offset-3">
          <input type="hidden" name="id" value="{$data.id ?? ''}">
          <button type="submit" class="btn btn-primary">提交</button>
          <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);">返回</button>
        </div>
      </div>
    </div><!-- panel-footer -->

  </form>
</div>
{/block}
{block name="js"}
  <script>
    function addattrs()
    {
      var num = $('#attrs_title').val();
      var fenpei = $('#fenpei_num').val();
      if(fenpei < num){
         swal({   
                title: "可分配数量不足",   
                text: "",   
                type: "error",  
            });
         return false;
      }
      var sheng = fenpei - num;
         var list=new Array();
        $("input[name='attrs_group[]']").each(function(){
            list.push($(this).attr('name'));
        });
    //console.log(list);
    var chang = list.length;
      var html=`<div class="form-group" id="attrs_group_`+chang+`">
        <label class="col-sm-3 control-label" ><input type="hidden" name="attrs_group[]" value="`+chang+`"><a href="javascript:;" onclick="del_div(`+chang+`)">删除</a>：</label>
        <div class="col-sm-2">
          <select class="form-control" name="shopid[]" required>
            <option value=""> --请选择铺-- </option>
            {volist name="shop" id="vo"}
            <option value="{$vo.id}">{$vo.title}</option>
            {/volist}
          </select>
        </div>
         <label class="col-sm-1 control-label">分配数量：</label>
         <div class="col-sm-3">
           <input type="text" class="form-control" id="attrs_title"  name="fenpei[]" value="`+num+`" readonly/>
         </div>
      </div>`;
      
      $('#tianjia').after(html);
      $('#fenpei_num').val(sheng);
    }
    function del_div(obj)
    {
      
      $("#attrs_group_"+obj).remove();
    }
  </script>
{/block}